package stream流第一遍.demo09;

import java.util.*;
import java.util.stream.Collectors;

/**
 * @author wql
 * @version 1.0
 * @date 2022/11/5 20:47
 */

public class Test {
    public static void main(String[] args) {
        List<Wql> list = new ArrayList<>();
        list.add(new Wql("张二",12,"男"));
        list.add(new Wql("李三",11,"男"));
        list.add(new Wql("王麻",3,"男"));
        list.add(new Wql("大炮",7,"男"));
        list.add(new Wql("益达",90,"男"));
        list.add(new Wql("只因",1000000001,"女"));
        //colect--搜集操作--元素的个数
      //  Long collect = list.stream().collect(Collectors.counting());
      //  System.out.println("collect = " + collect);

        //colect--搜集操作--根据条件搜集最大的元素
       // Optional<Wql> collect1 = list.stream().collect(Collectors.maxBy((o1, o2) -> o1.getAge() - o2.getAge()));
      //  System.out.println("collect1 = " + collect1);

        //colect--搜集操作--根据条件搜集最小的元素
      //  Optional<Wql> collect2 = list.stream().collect(Collectors.minBy((o1, o2) -> o1.getAge() - o2.getAge()));
      //  System.out.println("collect2 = " + collect2);

       // colect--搜集操作--元素的平均值( averagingInt、 averagingLong、 averagingDouble)
      //  Double collect3 = list.stream().collect(Collectors.averagingInt(item -> item.getAge()));
      //  Double collect3 = list.stream().collect(Collectors.averagingLong(item -> item.getAge()));
     //   Double collect3 = list.stream().collect(Collectors.averagingDouble(item -> item.getAge()));
     //   System.out.println("collect3 = " + collect3);

        //colect--搜集操作--求和（summingInt、 summingLong、 summingDouble）
       Integer collect = list.stream().collect(Collectors.summingInt(item -> item.getAge()));
        System.out.println("collect = " + collect);

    }
}
class Wql{
    private String name;
    private Integer age;
    private String sex;

    public Wql(String name, Integer age, String sex) {
        this.name = name;
        this.age = age;
        this.sex = sex;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Integer getAge() {
        return age;
    }

    public void setAge(Integer age) {
        this.age = age;
    }

    public String getSex() {
        return sex;
    }

    public void setSex(String sex) {
        this.sex = sex;
    }

    @Override
    public String toString() {
        return "Wql{" +
                "name='" + name + '\'' +
                ", age=" + age +
                ", sex='" + sex + '\'' +
                '}';
    }
}


